/**
 * 
 */
package info.niwota.profile.web;

import info.niwota.commons.acl.AccessPermission;
import info.niwota.webapp.acl.LabelContentProvider;
import info.niwota.webapp.acl.PermStore;
import android.content.Context;

/**
 * @author qiangli
 *
 */
public class ProfileLabelContentProvider extends LabelContentProvider {
	private PermStore store = null;

	@Override
	public boolean onCreate() {
		Context ctx = getContext();
		store = new PermStore(ctx);
		//
		return true;
	}

	@Override
	protected void store(String label, String perm, String emails) {
		store.store(label, perm, emails);
	}

	@Override
	protected AccessPermission[] loadPerms() {
		Label[] labels = Label.getLabels();
		AccessPermission[] perms = new AccessPermission[labels.length];
		for (int i = 0; i < labels.length; i++) {
			Label lab = labels[i];
			String[] pa = store.getPerm(lab.name);
			perms[i] = new AccessPermission();
			perms[i].label = lab.name;
			perms[i].perm = pa[0];
			perms[i].emails = pa[1];
			//other not supported yet
			perms[i].id = -1;
			perms[i].icon = null; 
			perms[i].desc = ""; 
		}
		return perms;
	}

}
